//#define __FORCE_TRACE__
//#define __FORCE_DEBUG__
//#define __FORCE_INFO__
#define THIS_FILE "fn_pveh.sqf"
#include <btc_macros.h>
TRACE_1("Start",_this);

private ["_array","_type","_x"];
//0 - first aid - create // [0,east,pos]
//1 - first aid - delete
_array = _this select 1;
_type  = _array select 0;
switch (true) do
{
	case (_type == 0) : 
	{
		private ["_side","_unit","_pos","_marker"];
		_side = _array select 1;
		_unit = _array select 3;
		if (_side == BTC_side) then 
		{
			_pos = _array select 2;
			_marker = createmarkerLocal [format ["FA_%1", _pos], _pos];
			format ["FA_%1", _pos] setmarkertypelocal "mil_box";
			format ["FA_%1", _pos] setMarkerTextLocal format ["F.A. %1", name _unit];
			format ["FA_%1", _pos] setmarkerColorlocal "ColorGreen";
			format ["FA_%1", _pos] setMarkerSizeLocal [0.3, 0.3];
			[_pos,_unit] spawn
			{
				_pos  = _this select 0;
				_unit = _this select 1;
				while {(!(isNull _unit) && (format ["%1", _unit getVariable "BTC_need_revive"] == "1"))} do
				{
					format ["FA_%1", _pos] setMarkerPosLocal getpos _unit;
					sleep 1;
				};
				deleteMarker format ["FA_%1", _pos];
			};
		};
	};
	case (_type == 1) : {(_array select 1) setDir 180;(_array select 1) playMoveNow "AinjPpneMstpSnonWrflDb_grab";};
	case (_type == 2) : 
	{
		private ["_injured"];
		_injured = (_array select 1);
		[_injured] spawn
		{
			_injured = _this select 0;
			_injured allowDamage false;
			WaitUntil {sleep 1; (isNull _injured) || (format ["%1", _injured getVariable "BTC_need_revive"] == "0")};
			_injured allowDamage true;
		};
	};
	case (_type == 3) : 
	{
		private ["_injured","_veh"];
		_injured = (_array select 1);
		_veh     = (_array select 2);
		if (name _injured == name player) then {_injured moveInCargo _veh};
	};
	case (_type == 4) : 
	{
		private ["_array_injured"];
		_array_injured = (_array select 1);
		{
			if (name player == name _x) then {
				unAssignVehicle player;
				player action ["eject", vehicle player];
				_spawn = [] spawn {
					sleep 0.5;player switchMove "ainjppnemstpsnonwrfldnon";
				};
			};
		} foreach _array_injured;
	};
	case (_type == 5) : 
	{
		private ["_array_injured","_injured","_healer"];
		_spawn = [(_array select 1),(_array select 2)] spawn
		{
			_injured = _this select 0;
			_healer  = _this select 1;
			_injured setPos (_healer modelToWorld [0,1,0]);				
			_injured setDir (getDir _healer + 180);
			_injured switchMove "AinjPfalMstpSnonWnonDnon_carried_up";
			WaitUntil {!Alive _healer || ((animationstate _healer == "acinpercmstpsraswrfldnon") || (animationstate _healer == "acinpercmrunsraswrfldf") || (animationstate _healer == "acinpercmrunsraswrfldr") || (animationstate _healer == "acinpercmrunsraswrfldl"))};
			_injured switchMove "AinjPfalMstpSnonWnonDf_carried_dead";
			sleep 0.2;
			_injured setDir 180;
		};
	};
	case (_type == 6) : 
	{
		private ["_array_injured"];
		_spawn = [(_array select 1)] spawn
		{
			(_this select 0) switchMove "AinjPfalMstpSnonWrflDnon_carried_down";
			sleep 3;
			if (format ["%1",(_this select 0) getVariable "BTC_need_revive"] == "1") then {(_this select 0) switchMove "ainjppnemstpsnonwrfldnon";};
		};
	};
	case (_type == 7) : 
	{
		private ["_injured","_cpr_bonus"];
		_injured = _array select 1;
		_cpr_bonus = _array select 2;
		if (name player == _injured) then {BTC_r_timeout = BTC_r_timeout + _cpr_bonus;};
	};
	case (_type == 8) : 
	{
		private ["_injured"];
		_injured = _array select 1;
		if (name player == _injured) then 
		{
			private ["_state","_bleed"];
			_state = (_injured getVariable "BTC_r_status");
			_bleed = (_state select 0) - 70;
			if (_bleed < 0) then {_bleed = 0;};
			_injured setVariable ["BTC_r_status",[0,_bleed,(_state select 2),(_state select 3),(_state select 4)],true];			
		};
	};
	case (_type == 9) : 
	{
		private ["_injured"];
		_injured = _array select 1;
		if (name player == _injured) then 
		{
			private ["_state","_bleed"];
			BTC_r_damage = 0;BTC_r_head = 0;BTC_r_damage_legs = 0;BTC_r_damage_hands = 0;player forceWalk false;BTC_r_med_effect = false;player setHit ["legs", 0];player setHit ["hands", 0];
		};
	};
	case (_type == 10) : 
	{
		private ["_injured","_anim"];
		_unit = _array select 1;
		_anim = _array select 2;
		_unit switchMove _anim;
	};
	case (_type == 100) : 
	{
		private ["_side","_vec","_var_name"];
		_side = _array select 1;
		if (tolower(_side) == BTC_side_str) then {
			_vec = _array select 2;
			_var_name = _array select 3;
			[_vec] call FUNC(addTeleportAction);
		};
	};
	case (_type == 101) : 
	{
		private ["_side","_vec","_var_name"];
		_side = _array select 1;
		if (tolower(_side) == BTC_side_str) then {
			_vec = _array select 2;
			_var_name = _array select 3;
			[_vec] call FUNC(addHealAction);
		};
	};
	case (_type == 102) : 
	{
		private ["_side","_vec","_var_name"];
		_side = _array select 1;
		if (tolower(_side) == BTC_side_str) then {
			_vec = _array select 2;
			_var_name = _array select 3;
			[_vec] call FUNC(addAmmoAction);
		};
	};
	case (_type == 200) : 
	{
		private ["_side","_box"];
		_side = _array select 1;
		_box = _array select 2;
		player reveal _box;
		[_box,_side] call FUNC(fillAmmoBox);
	};
};
TRACE("End");